package com.gxm.base.reflect;

import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.stream.Collectors;

/**
 * @author 郭训民
 * @description: TODO
 * @title: Demo
 * @projectName jsee
 * @date 2021/4/6 18:30
 */
public class Demo {

    @Test
    public void test01() throws NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException, ClassNotFoundException {
        ReflectDemo reflectDemo = new ReflectDemo();
        long beginTime = System.currentTimeMillis();
//        Class clazz = reflectDemo.getClass();
        Class clazz = Class.forName("com.gxm.base.reflect.ReflectDemo");
        Method method = clazz.getMethod("methodA", null);
//        reflectDemo.methodA();
        method.invoke(clazz.newInstance(), null);
        System.out.println("反射执行时间:" + (System.currentTimeMillis() - beginTime));
    }


    @Test
    public void test02() {
        try {
            //int i = 1/0;
            System.out.println("业务执行中!");
        } catch (Exception e) {
            throw e;
        } finally {
            System.out.println("finally,执行!");
        }
    }

    @Test
    public void test03() {
        long l1 = 6L;
        System.out.println(l1/1000);
        BigDecimal b1 = new BigDecimal(String.valueOf(l1));
        BigDecimal b2 = new BigDecimal(String.valueOf(1000D));

        System.out.println(b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP).doubleValue());
    }

    @Test
    public void test04() throws ParseException {
        //注意月份是MM
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        Date date1 = simpleDateFormat.parse("2019-09-02");
//        Date date2 = simpleDateFormat.parse("2019-09-02");
//        Ren ren1 = new Ren();
//        Ren ren2 = new Ren();
//        ren1.setDate(date1);
//        ren2.setDate(date2);
//        ArrayList<Object> objects = new ArrayList<>();
//        objects.add(date1);
//        objects.add(date2);
//        objects.stream().sorted(Comparator.comparing(Ren::getDate)).collect(Collectors.toList());
//////排序后输出
//        StudentInfo.printStudents(studentsSortName);

    }

    @Test
    public void test05(){
        int a=20;
        int b=5;
        int c= (int) (System.currentTimeMillis()%b);
        System.out.println("取模："+c);//取模：2

    }
}
class  Ren {

    private Date date;
    private String name;

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}